package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuInfoSaveVo;
import com.atguigu.gmall.product.vo.SpuInfoSaveVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "SKU管理")
@RequestMapping("/admin/product")
@RestController
public class SkuController {

    @Autowired
    SkuInfoService skuInfoService;


    @GetMapping("/list/{pn}/{ps}")
    public Result skuList(@PathVariable("pn") Long pn,
                                     @PathVariable("ps") Long ps){
        Page<SkuInfo> page  = new Page<>(pn,ps);

        Page<SkuInfo> result =  skuInfoService.page(page);
        return Result.ok(result);
    }

/*Sku大保存*/
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoSaveVo vo ){

        skuInfoService.saveSkuInfo(vo);
        return Result.ok();
    }

    /*上架*/
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){

        skuInfoService.changeOnSale(skuId,1);
        return Result.ok();
    }

    /*下架*/
    @GetMapping("/cancelSale/{skuId}")
    public Result canaelSale(@PathVariable("skuId") Long skuId){

        skuInfoService.changeOnSale(skuId,0);
        return Result.ok();
    }
}
